package com.stars.pao.springbook.model;

import lombok.Data;

@Data
public class Result<T> {
    private Integer code; //后端响应的状态，业务状态码 200 - 成功，-1 - 失败 -2 表示未登录
    private String errmsg;//后端发生错误的原因
    private T data;

    //成功
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setData(data);
        return result;
    }

    //失败
    public static <T> Result<T> error(T data, String errmsg) {
        Result<T> result = new Result<>();
        result.setData(data);
        result.setCode(-1);
        result.setErrmsg(errmsg);
        return result;
    }
    public static <T> Result<T> fail(String errmsg) {
        Result<T> result = new Result<>();
        result.setCode(-1);
        result.setErrmsg(errmsg);
        return result;
    }

    //未登录
    public static <T> Result<T> unLogin() {
        Result<T> result = new Result<>();
        result.setCode(-2);
        result.setErrmsg("用户未登录");
        return result;
    }

}
